﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using CharacterTrailLibrary.Interface;

namespace CharacterTrailLibrary.Impl
{
    /// <summary>
    /// 采用装饰模式，额外添加AOP操作对象
    /// </summary>
    public class ExcelImportorNewDecorator: IExcelImportor
    {
        public delegate void PrepareExcelImportEventHandler(DataTable dataTable);
        public delegate void PostExcelImportEventHandler(DataTable dataTable);


        public event PrepareExcelImportEventHandler PrepareExcelImport = null;

        protected void OnPrepareExcelImport(DataTable dataTable)
        {
            PrepareExcelImportEventHandler handler = PrepareExcelImport;
            if (handler != null) handler(dataTable);
        }

        public event PostExcelImportEventHandler PostExcelImport = null;

        protected void OnPostExcelImport(DataTable dataTable)
        {
            PostExcelImportEventHandler handler = PostExcelImport;
            if (handler != null) handler(dataTable);
        }

        public ExcelImportorNewDecorator(IExcelImportor excelImportor)
        {
            FExcelImportor = excelImportor;
        }

        public IExcelImportor FExcelImportor { get;private set; }

        public System.Data.DataTable GetDataTable(string fileName)
        {
            return FExcelImportor.GetDataTable(fileName);
        }

        public void ImportToDb(System.Data.DataTable dataTable)
        {
            OnPrepareExcelImport(dataTable);
            FExcelImportor.ImportToDb(dataTable);
            OnPostExcelImport(dataTable);
        }
    }
}
